package com.yaxin.heshanghui.activity;

import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;

import com.framework.Utils.ToastUtil;
import com.framework.Utils.Utils;
import com.yaxin.heshanghui.R;
import com.yaxin.heshanghui.base.BaseOnClickListener;
import com.yaxin.heshanghui.base.BiuooBaseActivity;
import com.yaxin.heshanghui.customview.TitleView;
import com.yaxin.heshanghui.utils.BiuooCustomProgressDialogUtils;


public class BiuooHomepageActivity extends BiuooBaseActivity implements ActivityCompat.OnRequestPermissionsResultCallback {

    private long exitTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Utils.setTranslucentStatus(this, true);
        Utils.setStatusBarTintDrawable(this,R.mipmap.biuoo_bg_top);
        setContentView(R.layout.biuoo_activity_main);
        initView();
    }


    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.leftLayout:
                BiuooCustomProgressDialogUtils.showProcessDialog(this, "正在识别");
                Utils.h.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        BiuooCustomProgressDialogUtils.dismissProcessDialog();
                        ToastUtil.getInstance().showToast("请手动输入号码!");
                    }
                }, 2000);
                break;
            case R.id.rightLayout:
                ToastUtil.getInstance().showToast("未添加扫码功能，请手动输入!");
//                BiuooCustomProgressDialogUtils.showProcessDialog(this, "跳转扫码");
//                Utils.h.postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        BiuooCustomProgressDialogUtils.dismissProcessDialog();
//                        ToastUtil.getInstance().showToast("未添加扫码功能，请手动输入!");
//                    }
//                }, 2000);
                break;
            case R.id.tv_input:
                startActivity(BiuooInputPhoneActivity.class);
                break;
            default:
                break;
        }
    }


    private void initView() {
        TitleView titleView = (TitleView) findViewById(R.id.titleView);
        titleView.setTitle("导购").setLeftOnClickListener(new BaseOnClickListener() {
            @Override
            protected void onBaseClick(View v) {
                finish();
            }
        });
    }


    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            if (System.currentTimeMillis() - this.exitTime > 2000L) {
                Toast.makeText(this.getApplicationContext(), this.getResources().getString(R.string.exist) + this.getResources().getString(R.string.app_name), Toast.LENGTH_SHORT).show();
                this.exitTime = System.currentTimeMillis();
            } else {
                // 返回主界面
                /**
                 * 退出登录,清空数据
                 */
                finish();
//                int pid = android.os.Process.myPid();
//                android.os.Process.killProcess(pid);
            }
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }

}
